package util

import (
	"errors"
	"github.com/beego/beego/v2/client/orm"
	"userrpc/internal/models"
)

func SelectUser(username string) error {
	o := orm.NewOrm()
	s := models.User{}
	o.QueryTable("user").Filter("username", username).One(&s)
	if s.Id > 0 {
		return errors.New("账号已被注册")
	}
	return nil
}
func Add(username, password, mobile string) error {
	o := orm.NewOrm()
	s := models.User{
		Username: username,
		Password: password,
		Mobile:   mobile,
	}
	_, err := o.Insert(&s)
	if err != nil {
		return errors.New("注册失败")
	}
	return nil
}
